<?php
class AI_Writer_API {
    private $api_url = 'https://chat.orderease.cn/api/proxy.php';
    
    public function generate_content($prompt) {
        $response = wp_remote_post($this->api_url, array(
            'body' => json_encode(array(
                'message' => $prompt,
                'stream' => false
            )),
            'headers' => array(
                'Content-Type' => 'application/json'
            ),
            'timeout' => 30
        ));

        if (is_wp_error($response)) {
            return array(
                'success' => false,
                'message' => $response->get_error_message()
            );
        }

        $body = wp_remote_retrieve_body($response);
        $data = json_decode($body, true);
        
        if (isset($data['result'])) {
            return array(
                'success' => true,
                'content' => $data['result']
            );
        } else {
            return array(
                'success' => false,
                'message' => $data['error'] ?? '生成内容失败'
            );
        }
    }
} 